<?php
namespace app\api\controller;

use app\common\controller\Api;
use think\Config;
use EasyWeChat\Factory;
/**
 * 微信接口
 */
class Wechat extends Api
{
    protected $noNeedLogin = ['oauthcallback', 'info'];
    protected $noNeedRight = '*';
    protected $config = [
            'app_id' => 'wx56237a44263fb136',
            'secret' => 'd7e84ccb6ae36a844887f9d506aa10f3',

            // 下面为可选项
            // 指定 API 调用返回结果的类型：array(default)/collection/object/raw/自定义类名
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/../../../runtime/log/wechat.log',
            ],
        ];
    public function _initialize()
    {
        parent::_initialize();

        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }

    }
    public function oauthcallback(){

    }
    public function info(){
        $code = $this->request->get("code");
        if($code){
            $app = Factory::miniProgram($this->config);
            $res = $app->auth->session($code);

            $this->success("", $res);

        }
    }
}
